#include "guiwidget.h"

CGuiWidget::CGuiWidget()
{
	m_v2f_Pos.x = m_v2f_Pos.y = 0;
	m_v2f_Dim.x = m_v2f_Dim.y = 0;
	
	m_Color.R = 153;
	m_Color.G = 204;
	m_Color.B = 255;
	m_Color.A = 50;
}

bool CGuiWidget::IsMouseOver()
{
	int32_t x, y;
	x = y = 0;
	CInputManager::GetMousePosition(x, y);

	return x >= m_v2f_Pos.x 
	&& x < m_v2f_Pos.x + m_v2f_Dim.x
	&& y >= m_v2f_Pos.y
	&& y < m_v2f_Pos.y + m_v2f_Dim.y;
}

bool CGuiWidget::WasMouseDownInside()
{
	int32_t x, y;
	x = y = 0;
	CInputManager::GetMouseDownPos(x, y);

	return x >= m_v2f_Pos.x 
	&& x < m_v2f_Pos.x + m_v2f_Dim.x
	&& y >= m_v2f_Pos.y
	&& y < m_v2f_Pos.y + m_v2f_Dim.y;
}

bool CGuiWidget::IsSelectable()
{
	return IsMouseOver() && WasMouseDownInside();
}

bool CGuiWidget::IsMouseDown()
{
	bool over = IsMouseOver();

	return (glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) && over;
}

void CGuiWidget::SetColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
	m_Color.R = r;
	m_Color.G = g;
	m_Color.B = b;
	m_Color.A = a;
}

CGuiWidget::~CGuiWidget()
{
	//
}
